package com.flong.juc.charter1;

import java.util.Random;

/**
 * @Author:liangjl
 * @Date: 2020/7/4-22:10
 * @Eamil:jilongliang@sina.com
 * @Description:
 * 优先级越高的一般会优先执行，一般情况是看CPU执行
 */
public class MyTest12 {

    public static void main(String[] args) {
        for (int i = 0; i < 5; i++) {
            Thread t = new MyTest12Thread();
            t.setName("A" + i);
            t.setPriority(Thread.MAX_PRIORITY);
            t.start();
            Thread t2 = new MyTest12Thread();
            t2.setName("B" + i);
            t2.setPriority(Thread.MIN_PRIORITY);
            t2.start();
        }
    }
}

class MyTest12Thread extends Thread {
    @Override
    public void run() {
        long start = System.currentTimeMillis();
        long count = 0;
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 50000; j++) {
                Random random = new Random();
                count += i * j + random.nextInt();
            }
        }
        long end = System.currentTimeMillis();
        System.out.println("线程名称：" + this.getName() + "执行完成使用" + (end - start) + "毫秒");

    }
}
